package model.dap.dao;

import java.util.ArrayList;
//import java.util.List;

import model.dap.domain.OrderHistory;
import model.dap.mapper.HistoryMapper;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import common.base.DaoConfig;

public class HistoryDAO implements HistoryMapper {

	//SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
	Logger log = Logger.getLogger(HistoryDAO.class);

	@Override
	public ArrayList<OrderHistory> selectHistoryFromDB(String consumerID) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class).selectHistoryFromDB(
					consumerID);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return null;
	}

	@Override
	public ArrayList<OrderHistory> selectHistoryFromDB_10(String consumerID) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.selectHistoryFromDB_10(consumerID);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return null;
	}

	@Override
	public ArrayList<OrderHistory> selectHistoryFromDB_20(String consumerID) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.selectHistoryFromDB_20(consumerID);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return null;
	}

	@Override
	public ArrayList<OrderHistory> selectHistoryFromDB_30(String consumerID) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.selectHistoryFromDB_30(consumerID);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return null;
	}

	@Override
	public int updateStatusOrderDeal(OrderHistory orderhistory) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.updateStatusOrderDeal(orderhistory);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return 0;
	}
	
	@Override
	public OrderHistory selectOrderHistory(int orderID) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.selectOrderHistory(orderID);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return null;
	}
	
	@Override
	public int updateEditNumberOrderedDeal(OrderHistory orderhistory) {
		SqlSession session = DaoConfig.getSqlSessionFactory().openSession();
		// TODO Auto-generated method stub
		try {
			return session.getMapper(HistoryMapper.class)
					.updateEditNumberOrderedDeal(orderhistory);
		} catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		} finally {
			session.commit();
			session.close();
		}
		return 0;
	}

}
